package com.xiaoma.reactor;

import reactor.core.publisher.Flux;

public class MySubscriberTest {

    @org.junit.Test
    public void testOut() {
        // 1.创建一个序列
        Flux<Integer> flux = Flux.range(1, 6)
                .map(i -> {
                    if (i <= 4) {
                        return i * 2;
                    }
                    throw new RuntimeException("数据超过了5！");
                });

        // 2.订阅
        MySubscriber ss = new MySubscriber();

        flux.subscribe(System.out::println,
                error -> System.out.println("Error:" + error),
                () -> System.out.println("Complete!"),
                s -> ss.request(2));

        flux.subscribe(ss);
    }

}
